package com.es.hr.salaryParameter;

import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.ActionSupport;

public class QuerySalaryParameterListAction   extends ActionSupport implements ServletRequestAware{

	private static final long serialVersionUID = 1L;
	HttpServletRequest request;
	 
	@SuppressWarnings("unchecked")
	public String execute()throws Exception{
		
		SalaryParameterBiz biz = new SalaryParameterBiz();
		ArrayList<HashMap<String,String>> list = biz.getSalaryParameterList();
		ArrayList<SalaryParameterBean> spBean = new ArrayList<SalaryParameterBean>();
		
		int inx =0;
		String salaryType_old="";
		SalaryParameterBean bean=null;
		ArrayList<HashMap<String,String>> beanList = new ArrayList<HashMap<String,String>>();
		for(HashMap<String,String> map:list){
			HashMap<String,String> paramete = new HashMap<String,String>();
			String salary_type = map.get("salary_type");
			String salary_percent = map.get("salary_percent");
			String paramete_type = map.get("paramete_type");
			
			paramete.put("paramete_start", map.get("paramete_start")) ;
			paramete.put("paramete_end", map.get("paramete_end")) ;
			paramete.put("paramete_percent", map.get("paramete_percent")) ;	
			
			if(!salaryType_old.endsWith(salary_type)){
				if(!salaryType_old.equals("")){
					bean.setParamete((ArrayList<HashMap<String,String>>)beanList.clone());
					spBean.add(bean);
				}
				bean = new SalaryParameterBean();
				beanList.clear();
				bean.setSalary_type(salary_type);
				bean.setParamete_type(paramete_type);
				bean.setSalary_percent(salary_percent);
				bean.setInx(inx++);
			}
			beanList.add((HashMap<String,String>)paramete.clone());
			salaryType_old = salary_type;
		}
		bean.setParamete((ArrayList<HashMap<String,String>>)beanList.clone());
		spBean.add(bean);
		String message = (String)request.getAttribute("message");
		if(message!=null)
			   request.setAttribute("message", message);
		request.setAttribute("spBean", spBean);
		request.setAttribute("num", spBean.size()-1);
		return "success";
	}

	public void setServletRequest(HttpServletRequest request) {
	     this.request = request;
	}
	
}